Binary tree
Check Completeness of a Binary Tree (LC958)
Comments CountSolution
Flip Equivalent Binary Trees (LC951)
Comments CountProblem description
For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.
Complete Binary Tree Inserter
binary tree depth first search
Comments CountProblem description
A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.
Smallest Subtree with all the Deepest Nodes (LC865)
leetcode algorithm binary tree depth first search
Comments CountProblem description
Given a binary tree rooted at root, the depth of each node is the shortest distance to the root.
All Nodes Distance K in Binary Tree (LC863)
leetcode algorithm depth first search binary tree
Comments CountProblem description
We are given a binary tree (with root node root), a target node, and an integer value K.
Flip Binary Tree to Match Preorder Traversal (LC971)
depth first search preorder traversal binary tree
Comments CountProblem description
Given a binary tree with N nodes, each node has a different value from {1, …, N}.
Binary Tree Pruning (LC814)
leetcode algorithm binary tree depth first search post order traversal
Comments CountProblem description
We are given the head node root of a binary tree, where additionally every node’s value is either a 0 or a 1.
Minimum Distance Between BST Nodes (LC783)
leetcode algorithm in order traversal binary tree
Comments CountProblem description
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree.
Insert into Binary Search Tree (LC701)
algorithm leetcode depth first search binary tree
Comments CountProblem description
Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BST.
Print Binary Tree (LC655)
binary tree recursion depth first search leetcode algorithm
Comments CountProblem description
Print a binary tree in an m*n 2D string array following these rules:
Find Duplicate Subtrees (LC652)
leetcode algorithm depth first search binary tree
Comments CountProblem description
Given a binary tree, return all duplicate subtrees. For each kind of duplicate subtrees, you only need to return the root node of any one of them.
Sum of Left Leaves (LC404)
leetcode algorithm binary tree depth first search tree traversal
Comments CountProblem description
Find the sum of all left leaves in a given binary tree.
House Robber III (LC337)
leetcode algorithm binary tree dynamic programming
Comments CountProblem description
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that “all houses in this place forms a binary tree”. It will automatically contact the police if two directly-linked houses were broken into on the same night.
Serialize and Deserialize Binary Tree (LC297)
leetcode algorithm binary tree
Comments CountProblem description
Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.
Lowest Common Ancestor of a Binary Tree (LC236)
leetcode algorithm binary tree recursion
Comments CountProblem description
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.